home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / areuh.tar / areuh / assembler / apass.c < prev    next >
C/C++ Source or Header  |  1990-10-10  |  3KB  |  145 lines

  1. /*
  2.  * Authors :
  3.  *   Pierre DAVID (pda@masi.ibp.fr or pda@frunip62.bitnet)
  4.  *   Janick TAILLANDIER
  5.  *
  6.  * This program can be freely used or distributed as long as this
  7.  * note is kept.
  8.  *
  9.  * This program is provided "as is".
  10.  */
  11.  
  12. /******************************************************************************
  13.  
  14.                 AREUH ASSEMBLER
  15.  
  16.                 PASS PROCESSING
  17.  
  18.  
  19. pass
  20.  
  21. ******************************************************************************/
  22.  
  23. #include "aglobal.h"
  24. #include "agen.h"
  25.  
  26. extern struct mnemo_desc *find_mnemo() ;
  27. extern int read_line();
  28. extern void parse_line(), ps_label(), process_mnemo(),
  29.         l_new_page(), l_print(), o_print() ;
  30. extern struct symbol *add_label() ;
  31.  
  32. void ps_line() ;
  33.  
  34.  
  35. /******************************************************************************
  36.  
  37.                      PASS
  38.  
  39.  
  40. synopsis : void pass()
  41. description :
  42.  
  43. ******************************************************************************/
  44.  
  45. void pass()
  46. {
  47.     uchar line[MAXLEN+1];
  48.     int c;
  49.  
  50.     pc = 0 ;
  51.     prev_test = 0 ;
  52.     running = 1 ;
  53.     exec = 1 ; in_if = in_else = 0 ;
  54.  
  55.     while (running)
  56.     {
  57.     c = read_line (fd_s, line) ;
  58.     error_this_line = 0 ;
  59.     if (c) running = 0 ;
  60.     else ps_line (line) ;
  61.     }
  62.  
  63.     if (passnb==1)
  64.     {
  65.     add_label("FiLeNd", pc, "", LREL, 0) ;
  66.     }
  67. }
  68.  
  69.  
  70. /******************************************************************************
  71.  
  72.                   PS_LINE
  73.  
  74.  
  75. synopsis : void ps_line (line)
  76.        uchar *line
  77. description : parses the line read from the input (breaks the line into three
  78.           components), processes the label if necessary, processes the
  79.           mnemonic if necessary, and does the listing and object file
  80.           actualization, if pass one.
  81.  
  82. ******************************************************************************/
  83.  
  84. void ps_line (line)
  85. uchar *line ;
  86. {
  87.     uchar label[LBLLEN+2], mnemo[7], modif[MAXLEN+1] ;
  88.     struct mnemo_desc *ad ;
  89.  
  90.     parse_line (line, label, mnemo, modif) ;
  91.  
  92.     if (!exec)
  93.     {
  94.     if ( (strcmp(mnemo, "IF"))&&
  95.          (strcmp(mnemo, "ELSE"))&&
  96.          (strcmp(mnemo, "ENDIF"))&&
  97.          (strcmp(mnemo, "END")) )
  98.         return ;      /* Neither IF nor ELSE nor ENDIF */
  99.     }
  100.     if (*label)
  101.     ps_label (label, mnemo, modif) ;
  102.  
  103.     *gen_code = EOL ;
  104.     gen_len = 0 ;
  105.  
  106.     if (*mnemo)
  107.     {
  108.     ad = find_mnemo (mnemo) ;
  109.     if (ad)
  110.     {
  111.         gen_len = ad->m_len ;
  112.         switch (passnb)
  113.         {
  114.         case 1 :
  115.             if (!((ad->m_flag)&F_LSET))
  116.              ps_mnemo (line, modif, ad) ;
  117.             break ;
  118.         case 2 :
  119.             strcpy (gen_code, ad->m_code) ;
  120.             ps_mnemo (line, modif, ad) ;
  121.             if ((prev_test)&&(!(ad->m_flag & F_GOYS)))
  122.             error (WRNYES, "") ;     /* GOYES or RTNYES required */
  123.             break ;
  124.         }
  125.     }
  126.     else
  127.     {
  128.         error (WRNOPC, "") ;       /* unknown oopcode */
  129.         if (prev_test)
  130.         error (WRNYES, "") ;     /* GOYES or RTNYES required */
  131.     }
  132.     }
  133.     else ad = (struct mnemo_desc *) NULL ;
  134.  
  135.     if (passnb==2)
  136.     {
  137.     if ((cntlist)&&(print_this_line++))
  138.         l_print (pc, gen_code, line, F_PC+F_LN+F_GC+F_TL) ;
  139.     o_print (gen_code, gen_len) ;
  140.     if (ad) prev_test = ((ad->m_flag)&F_RETY) ? 1 : 0 ;
  141.     }
  142.  
  143.     pc += gen_len ;
  144. }
  145.